using System;
using UnityEngine;
using UnityEngine.UI;

using MiniAnimation;
public class DebugActionUI : MonoBehaviour
{





    public GameObject testPanel;

    public Transform testParent, testBtnTemplete;




    private UnityEngine.Vector2 defaultposition;
    private void Start()
    {
        (this.transform as UnityEngine.RectTransform).ForceUpdateRectTransforms();
        this.defaultposition = (this.testPanel.transform as UnityEngine.RectTransform).anchoredPosition;
    }

    private void Awake()
    {
        DebugAction.AddActionEvent += this.AddAction;

        this.testBtnTemplete.gameObject.SetActive(false);

        this.testPanel.SetActive(true);
    }

    private void OnDestroy()
    {
        DebugAction.AddActionEvent -= this.AddAction;
    }



    private void AddAction(string name, Action action)
    {
        GameObject obj = Instantiate(this.testBtnTemplete.gameObject, this.testParent);
        obj.SetActive(true);
        obj.gameObject.name = name;
        var btn = obj.GetComponent<Button>();
        btn.onClick.AddListener(() =>
        {
            action();
        });
        var textSetor = obj.transform.GetComponentInChildren<Text>();
        textSetor.text = name;
    }

}
public class DebugAction
{
    public static Action<string, Action> AddActionEvent;
    public static void AddAction(string name, Action action)
    {
        DebugAction.AddActionEvent?.Invoke(name, action);
    }
}